﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Timers;
using System.IO;
using System.Net;
using System.Xml;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Collections;
using System.Drawing;
using System.Diagnostics;
using System.Web;
using NetDimension.Weibo;
using NetDimension.Json;
using NetDimension.Json.Linq;


namespace WeatherGod
{
    //class WEATHER
    //{
    //    public int Code { get { return _Code; } set { _Code = value; } } private int _Code;
    //    public string Page { get { return _Page; } set { _Page = value; } } private string _Page;
    //} 
    public partial class Form1 : Form
    {
        static string LoginName = string.Empty;
        static string PassWord = string.Empty;
        static string AppKey = string.Empty;
        static string AppSecret = string.Empty;
        static string CallbackUrl = string.Empty;
        static string AccessToken = string.Empty;

        static long AtMaxId = 0;
        static long SearchMaxId = 0;

        static string WeiboCnUid = string.Empty;
        static string WeiboCnGSID = string.Empty;
        static NetDimension.Weibo.Entities.user.Entity MyUserInfo = null;
        static OAuth oauth_tianqi = null;
        static Client Weibo_tianqi = null;
        static Client Weibo_Joke = null;

        static string dataBaseFile = "Databases/Weibo.sqlite";
        static string waterMarkFile = "watermark.jpg";
        static System.Timers.Timer t = new System.Timers.Timer();
        static string myUid = "";
        static string myNickName = "";
        static Random ro = new Random();

        static int atCount = 0;
        static List<string> listx = new List<string>();

        static bool AutoComment = false;    //自动评论
        static bool AutoWaterMark = false;  //自动加水印
        static bool SyncPM25ToDB = true;   //同步PM25数据
        static bool FollowLimit = false;    //达到接口上限或其他限制
        static int FollowLimitFreq = 5;     //首次最大频率5分钟
        static int CommentLimit = 0;
        static bool validGsid = true;

        NotifyIcon notifyicon = new NotifyIcon();   //创建托盘图标对象 
        ContextMenu notifyContextMenu = new ContextMenu();//创建托盘菜单对象 

        public Form1()
        {
            InitializeComponent();
            Logger.form1 = this;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //测试代码
            //GetWeatherInfoNodeFromXML();

            
            //读取配置
            //LoginName = XML.Read("LoginName");
            LoginName = XML.ReadExt("","User", "LoginName");
            PassWord = XML.ReadExt("", "User", "PassWord");
            AccessToken = XML.ReadExt("", "User", "AccessToken");
            AppKey = XML.ReadExt("", "App", "AppKey");
            AppSecret = XML.ReadExt("", "App", "AppSecret");
            CallbackUrl = XML.ReadExt("", "App", "CallbackUrl");

            AtMaxId = Convert.ToInt64(XML.ReadExt("", "MID", "AtMaxId"));
            SearchMaxId = Convert.ToInt64(XML.ReadExt("", "MID", "SearchMaxId"));

            WeiboCnUid = XML.ReadExt("", "WeiboCn", "Uid");
            WeiboCnGSID = XML.ReadExt("", "WeiboCn", "GSID");

            if (LoginName == "" || PassWord == "" || AppKey == "" || AppSecret == "" || CallbackUrl == "")
            {
                Logger.logger("配置信息不完整，程序退出！");
                return;
            }

            //验证数据库文件
            if (!Sqlite.CheckDbFile(dataBaseFile))
            {
                Logger.logger("数据库文件不存在，程序退出！");
                return;
            }

            //验证授权
            if (!GetAccessToken())
            {
                Logger.logger("无法获得授权，程序退出！");
                return;
            }
            else
            {
                Weibo_tianqi = new Client(oauth_tianqi);
                WeiboOauth2_Joke(); //for weibo joke
                Thread.Sleep(1000);
            }

            //获取自身信息
            try
            {
                var entity_RateLimitStatus = Weibo_tianqi.API.Entity.Account.RateLimitStatus();
                Logger.logger("接口剩余调用次数：" + entity_RateLimitStatus.RemainingIPHits.ToString());
                myUid = Weibo_tianqi.API.Entity.Account.GetUID();
                MyUserInfo = Weibo_tianqi.API.Entity.Users.Show(myUid);
                myNickName = MyUserInfo.ScreenName;
                //Logger.logger("uid：" + myUid + ", 昵称：" + myNickName);
                this.notifyIcon1.Text = myNickName;
                this.Text = myNickName;
                button1.Enabled = true;

                
#if DEBUG
                //DebugModeTest();
                //FollowQunUser();
                //ReplyWeiboByKeyword("天气");
                //ReplyWeiboAtMe();
                //SyncWeibo("1713926427");
                //CommnetWeibo("1197161814", "test");

                //string topUid = "1266321801,1704116960,1195242865,1192329374,1282005885";
                //string[] splittopUid = topUid.Split(',');

                //for (int i = 0; i < splittopUid.Length; i++)
                //{
                //    GetAtSomebodyFromUid(splittopUid[i]);
                //}
                //Logger.logger("完成临时任务，退出！");

                //return;
#endif

            }
            catch (Exception ex)
            {
                Logger.logger("调用API错误：" + ex.Message + "，程序退出！");
                return;
            }

            #region timer
            try
            {
                t.Interval = 1000 * 60;      //设置间隔时间为1分钟
                //t.Interval = 1000;          //调试时间：1秒钟
                t.Elapsed += new ElapsedEventHandler(TimerElapsedEvent);   //到达时间的时候执行事件； 
                t.AutoReset = true;         //设置是执行一次（false）还是一直执行(true)； 
                t.Start();                  //启动Timer对象； 
            }
            catch (Exception ex)
            {
                Logger.logger("定时异常：" + ex.Message);
                t.Stop();
            }
            #endregion
        }

        #region Auth
        static bool GetAccessToken()
        {
            if (string.IsNullOrEmpty(AccessToken))
            {
                oauth_tianqi = Authorize();
                oauth_tianqi.ClientLogin(LoginName, PassWord);
                if (!string.IsNullOrEmpty(oauth_tianqi.AccessToken))
                {
                    //Logger.logger("获取AccessToken成功！ " + oauth.AccessToken);
                    XML.Write("AccessToken", oauth_tianqi.AccessToken);
                    //Logger.logger("AccessToken已保存。");
                    return true;
                }
                else
                {
                    Logger.logger("获取AccessToken失败！");
                    return false;
                }
            }
            else//如果配置文件中保存了AccesssToken
            {
                //Logger.logger("配置文件中有AccessToken: " + AccessToken);
                oauth_tianqi = new OAuth(AppKey, AppSecret, AccessToken, "");	//用Token实例化OAuth无需再次进入验证流程
                //Logger.logger("验证Token有效性...");
                TokenResult result = oauth_tianqi.VerifierAccessToken();	//测试保存的AccessToken的有效性
                if (result == TokenResult.Success)
                {
                    //Logger.logger("AccessToken有效！");
                    return true;
                }
                else
                {
                    Logger.logger("AccessToken无效！因为：" + result);
                    XML.Write("AccessToken", string.Empty);
                    Logger.logger("开始重新授权！");
                    oauth_tianqi = Authorize();
                    if (!string.IsNullOrEmpty(oauth_tianqi.AccessToken))
                    {
                        Logger.logger("获取AccessToken成功！ " + oauth_tianqi.AccessToken);
                        XML.Write("AccessToken", oauth_tianqi.AccessToken);
                        //Logger.logger("AccessToken已保存。");
                        return true;
                    }
                    else
                    {
                        Logger.logger("获取AccessToken失败！");
                        return false;
                    }
                }
            }

        }
        static OAuth Authorize()
        {
            OAuth o = new OAuth(AppKey, AppSecret, CallbackUrl);
            if (!o.ClientLogin(LoginName, PassWord))
            {
                Logger.logger("授权登录失败，请检查配置是否正确！");
            }
            return o;
        }
        static Client WeiboOauth2_Joke()
        {
            string username = "118134555@qq.com";
            string password = "taojin1021";
            OAuth oauth_joke = new OAuth("2027761570", "5042214816d14b2d9e8ae8255f96180d", "https://api.weibo.com/oauth2/default.html");
            if (!oauth_joke.ClientLogin(username, password))
            {
                Logger.logger("错误：" + username + " 登录失败！！！");
            }
            else
            {
                Weibo_Joke = new Client(oauth_joke);
                string JokeUid = Weibo_Joke.API.Entity.Account.GetUID();
                var JokeInfo = Weibo_Joke.API.Entity.Users.Show(JokeUid);
                Logger.logger(JokeInfo.Name+ " 已登录！");
            }
            return Weibo_Joke;


        }
        #endregion

        #region Start
        private void button1_Click(object sender, EventArgs e)
        {
            var statusInfo = Weibo_tianqi.API.Entity.Statuses.Update(textBox1.Text);
            textBox1.Text = "";
            Logger.logger("发微成功。Text:" + statusInfo.Text);
        }
        #endregion

        #region Timer
        static void TimerElapsedEvent(object sender, ElapsedEventArgs e)
        {
            //自定义时间任务
            DateTime iNow = DateTime.Now;
            string iYear = iNow.Year.ToString();
            string iMonth = iNow.Month.ToString();
            string iDay = iNow.Day.ToString();
            string iHour = iNow.ToString("HH");
            string iMinute = iNow.ToString("mm");
            string iSecond = iNow.Second.ToString();
            string sendTime = iHour + iMinute;

            List<string> listTimer = new List<string>();

            try
            {
                //晚上也要睡觉嘛
                if (iNow.Hour >= 0 && iNow.Hour < 8)
                {
                    return;
                }

                if (iNow.Hour == 23 && iNow.Minute == 59)
                {
                    FollowLimit = false; //清除关注限制，复位
                }

                //时辰
                if (iNow.Hour == 8 && iNow.Minute == 0)
                {
                    SendDailyTips();
                }

                //风雨令
                if (iNow.Hour == 20 && iNow.Minute == 00)
                {
                    SendFengYuLing();
                }

                #region 刷粉
                //每15分钟刷粉
                if (iNow.Hour >=12 && (iNow.Minute - 3) % 15 == 0 && !FollowLimit && MyUserInfo.FriendsCount < 1850)
                {
                    if (validGsid)
                    {
                        FollowQunUser();
                    }
                }
                #endregion

                #region PM2.5
                //每小时的15分同步PM2.5数据
                if (iNow.Minute == 15)
                {
                    UpdatePM25ToDataBase();
                }
                //每2小时30分发布PM25数据
                //if (SyncPM25ToDB && (iNow.Hour % 2 == 0 && iNow.Minute == 30))
                //{
                //    SendMainCityPM25();
                //}
                #endregion

                #region 自动评论
                //每10分钟回复评论
                if ((iNow.Minute - 2) % 9 == 0)
                {
                    CommentLimit = 0;
                    ReplyWeiboAtMe();
                    if (validGsid)
                    {
                        RandomReplyWeiboByKeyword("天气"); 
                    }
                    
                }
                #endregion

                #region JOKE
                //20分钟同步一个微博
                if ((iNow.Minute + 7) % 30 == 0)
                {
                    SyncWeibo(Weibo_Joke, "1713926427");
                }
                #endregion

                //Dictionary<string, string> twitter_tbs = Sqlite.SearchCurrentWeibo(dataBaseFile);
                //if (twitter_tbs.Count > 0)
                //{
                //    if (twitter_tbs["Forward"] == "")
                //    {
                //        Logger.logger("获得发布内容。类型：" + ((twitter_tbs["Picture"] == "") ? "Text" : "Text + Picture"));
                //    }
                //    else
                //    {
                //        Logger.logger("获得转发内容。");
                //    }
                //    SendWeibo(twitter_tbs);
                //}
                

            }
            catch (Exception ex)
            {
                Logger.logger("定时任务异常：" + ex.Message);
            }
        }
        #endregion

        #region AT
        static void GetAtSomebodyFromUid(string topUid)
        {
            if (atCount >= 100000)
            {
                return;
            }
            try
            {
                IEnumerable<NetDimension.Weibo.Entities.user.Entity> activeIds = Weibo_tianqi.API.Entity.Friendships.FollowersInActive(topUid, 200);
                foreach (var activeId in activeIds)
                {
                    DateTime dtNow = DateTime.Now;
                    //DateTime dtCreate = DateTime.ParseExact("Fri Dec 21 09:30:23 +0800 2012", "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);
                    DateTime dtCreate = DateTime.ParseExact(activeId.Status.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);
                    TimeSpan ts1 = new TimeSpan(dtNow.Ticks);
                    TimeSpan ts2 = new TimeSpan(dtCreate.Ticks);
                    TimeSpan ts = ts1.Subtract(ts2).Duration();

                    if (Convert.ToInt32(activeId.FollowersCount) > 1000 //粉丝数大于3000
                        && (ts.Days < 3)                                //最近更新小于3天
                        && (activeId.ScreenName.Length < 10)            //名字长度小于10
                        && !Regex.IsMatch(activeId.ScreenName, "用户|粉|最|城|市|省|国|警|商|司|车|官|微|榜|娱|笑|店|团|牌|超|潮|典|购|折|集|禁|精|录|尚|搜|食|肥|瘦|淘|藤|网|裙|衣|鞋|秒|新", RegexOptions.IgnoreCase)
                        )
                    {
                        atCount += 1;
                        bool getduplicated = false;
                        foreach (string curUid in listx) // Loop through List with foreach
                        {
                            if (curUid == activeId.ID)
                            {
                                getduplicated = true;
                                break;
                            }
                        }
                        if (!getduplicated)
                        {
                            listx.Add(activeId.ID);
                            Logger.logger(atCount.ToString() + "\tu:" + activeId.ID + " f:" + activeId.FollowersCount + "\tn:" + activeId.ScreenName);
                            if (activeId.FollowersCount > 3000)
                            {
                                Thread.Sleep(ro.Next(15000, 30000));
                                GetAtSomebodyFromUid(activeId.ID);
                            }
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                string abcd = ex.Message;
            }
        }
        static string GetATSomboby()
        {
            try
            {
                StreamReader objReader = new StreamReader("AtList.txt");
                string sLine = "";
                ArrayList LineList = new ArrayList();
                while (sLine != null)
                {
                    sLine = objReader.ReadLine();
                    if (sLine != null && !sLine.Equals(""))
                        LineList.Add(sLine);
                }
                objReader.Close();
                return LineList[ro.Next(0, LineList.Count - 1)].ToString();
            }
            catch (Exception ex)
            {
                Logger.logger("GetATSomboby error " + ex.Message);
                return string.Empty;
                //throw(new Exception("GetATSomboby error " + ex.Message);
            }

        }
        static string AddATSomebody(string weiboText)
        {
            string result = string.Empty;
            try
            {
                string sb = GetATSomboby();

                if (weiboText.Length > 90 || weiboText.Contains("@"))
                {
                    return weiboText;
                }
                else if (Regex.IsMatch(weiboText, "（转）|「转」|\\(转\\)"))
                {

                    result = Regex.Replace(weiboText, "（转）|「转」|\\(转\\)", (sb != "") ? (" @" + sb + " ") : "", RegexOptions.IgnoreCase);
                    return result;
                }
                else if (Regex.IsMatch(weiboText, "via", RegexOptions.IgnoreCase))
                {
                    result = Regex.Replace(weiboText, "via |via", "via @", RegexOptions.IgnoreCase);
                    return result;
                }
                else if (Regex.IsMatch(weiboText, "by", RegexOptions.IgnoreCase))
                {
                    result = Regex.Replace(weiboText, "by |by", "by @", RegexOptions.IgnoreCase);
                    return result;
                }
                else
                {
                    result = weiboText + " @" + sb;
                }

            }
            catch (Exception ex)
            {
                Logger.logger("AddATSomebody error " + ex.Message);
                result = weiboText;
                //throw (new Exception("AddATSomebody: " + text + ", Error:" + ex.Message));
            }
            return result;
        }
        static string RemoveATSomebody(string text)
        {
            string result = string.Empty;
            try
            {
                result = Regex.Replace(text, "@.+?投稿", "", RegexOptions.IgnoreCase);
            }
            catch (Exception ex)
            {
                throw (new Exception("Regex.Replace: " + text + ", Error:" + ex.Message));
            }
            return result;
        }
        #endregion AT

        #region Weibo
        static void SyncWeibo(Client weiboClient, string uid)
        {
            Logger.logger("开始同步微博！");
            DateTime dtNow = DateTime.Now;
            bool forward = false;
            int checkDuplicateLength = 5;
            //DateTime dtCreate = DateTime.ParseExact("Fri Dec 21 09:30:23 +0800 2012", "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);

            NetDimension.Weibo.Entities.status.Collection myTimeLine = weiboClient.API.Entity.Statuses.UserTimeline(weiboClient.API.Entity.Account.GetUID(), "", "", "", 50);
            NetDimension.Weibo.Entities.status.Collection hisTimeLine = weiboClient.API.Entity.Statuses.UserTimeline(uid, "", "", "", 50);

            //如果自已发的微博比较热门，就自己转发一次
            foreach (var myItem in myTimeLine.Statuses)
            {
                DateTime dtCreate = DateTime.ParseExact(myItem.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);
                TimeSpan ts1 = new TimeSpan(dtNow.Ticks);
                TimeSpan ts2 = new TimeSpan(dtCreate.Ticks);
                TimeSpan ts = ts1.Subtract(ts2).Duration();

                if (ts.TotalHours > 23.9 && ts.TotalHours < 24.1 && myItem.RepostsCount >= 3)
                {
                    forward = true;
                    Dictionary<string, string> twitter_tbs = new Dictionary<string, string>();
                    twitter_tbs.Add("Forward", myItem.ID);
                    twitter_tbs.Add("Text", "");
                    twitter_tbs.Add("Picture", "");
                    SendWeibo(weiboClient, twitter_tbs);
                    break;
                }
            }

            //没有获得转发
            if (!forward)
            {
                //检查是否重复
                foreach (var hisItem in hisTimeLine.Statuses)
                {
                    bool getDuplicated = false;

                    DateTime dtCreate = DateTime.ParseExact(hisItem.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);
                    TimeSpan ts1 = new TimeSpan(dtNow.Ticks);
                    TimeSpan ts2 = new TimeSpan(dtCreate.Ticks);
                    TimeSpan ts = ts1.Subtract(ts2).Duration();

                    if (hisItem.RetweetedStatus != null || ts.TotalHours > 24 || hisItem.RepostsCount < 2000
                        || Regex.IsMatch(hisItem.Text, "冷笑话|淘宝|网购|下载|推荐|私信|更多|夜猫子们|赐句|果粉|推荐|错误|安卓|app|ＡＰＰ|免邮|面膜|营销|代言|参加|免费|星座|\\#|卫视|物流|客服|联通|《|》|汽车"))
                    {
                        continue;
                    }
                    foreach (var myItem in myTimeLine.Statuses)
                    {
                        if (hisItem.Text.Contains(myItem.Text.Substring(0, (myItem.Text.Length < checkDuplicateLength) ? myItem.Text.Length : checkDuplicateLength)))
                        {
                            getDuplicated = true;
                            break;
                        }
                    }
                    if (!getDuplicated)
                    {
                        Dictionary<string, string> twitter_tbs = new Dictionary<string, string>();
                        twitter_tbs.Add("Forward", string.Empty);
                        twitter_tbs.Add("Text", AddATSomebody(hisItem.Text));
                        twitter_tbs.Add("Picture", hisItem.OriginalPictureUrl);
                        SendWeibo(weiboClient, twitter_tbs);
                        break;
                    }
                }
            }
            Logger.logger("结束同步微博！");
        }
        static void SendWeibo(Client weibo_client, Dictionary<string, string> twitter)
        {
            NetDimension.Weibo.Entities.status.Entity statusInfo = null;
            try
            {
                //转发
                //twitter["Forward"] 使用16位数字
                if (!String.IsNullOrEmpty(twitter["Forward"]))
                {
                    statusInfo = weibo_client.API.Entity.Statuses.Repost(twitter["Forward"], twitter["Text"], 3);
                }
                //发送
                else
                {
                    if (!String.IsNullOrEmpty(twitter["Picture"]))
                    {
                        //高级授权，直接调用高级接口发送 图文微博,接口有问题，发送很高的图片，会被缩小
                        //确定来源的图片才可以发
                        if (false && Regex.IsMatch(AppKey, "82966982|2323547071", RegexOptions.IgnoreCase))
                        {
                            statusInfo = weibo_client.API.Entity.Statuses.UploadUrlText(twitter["Text"], twitter["Picture"]);
                        }
                        else //否则自己下载图片，本地上传图片发送
                        {
                            string DownloadedFile = Picture.DownloadPicture(twitter["Picture"]);
                            if (false && AutoWaterMark && DownloadedFile.Contains(".jpg"))
                            {
                                string FileWithWater = WaterMark.AddImageSignPic(DownloadedFile, waterMarkFile, 9, 100, 6);
                                DownloadedFile = FileWithWater;
                            }
                            if (DownloadedFile != "")
                            {
                                byte[] OpenedPicture = Picture.OpenFile(DownloadedFile);
                                if (OpenedPicture != null)
                                {
                                    statusInfo = weibo_client.API.Entity.Statuses.Upload(twitter["Text"], OpenedPicture);
                                }
                            }
                            else
                            {
                                Logger.logger("错误，DownloadedFile:" + DownloadedFile);
                            }
                        }
                    }
                    else
                    {
                        statusInfo = weibo_client.API.Entity.Statuses.Update(twitter["Text"]);
                    }
                }
                
                if (statusInfo != null)
                {
                    Logger.logger("发布成功。Text:" + statusInfo.Text.Substring(0, (statusInfo.Text.Length < 20) ? statusInfo.Text.Length : 20));
                    //自动评论李开复
                    if (AutoComment)
                    {
                        CommnetWeiboViaUid("1197161814", statusInfo.Text.Substring(0, (statusInfo.Text.Length < 100) ? statusInfo.Text.Length : 100) + " 更多笑话请关注我的微博..."); 
                    }
                }
            }
            catch (WeiboException ex)
            {
                Logger.logger("发布失败！错误码：" + ex.ErrorCode + " 原因: " + ex.Message);
            }
            catch (Exception ex)
            {
                Logger.logger("其它错误：" + ex.Message);
            }
        }

        static void CommnetWeiboViaUid(string uid, string comment)
        {
            try
            {
                NetDimension.Weibo.Entities.user.Entity usershow = Weibo_tianqi.API.Entity.Users.Show(uid);
                NetDimension.Weibo.Entities.comment.Entity createComment = Weibo_tianqi.API.Entity.Comments.Create(usershow.Status.ID, comment);
                Logger.logger("评论成功。Text:" + createComment.Text.Substring(0, (createComment.Text.Length < 10) ? createComment.Text.Length : 10));
            }
            catch (WeiboException ex)
            {
                Logger.logger("评论失败！错误码：" + ex.ErrorCode + " 原因: " + ex.Message);
            }
            catch (Exception ex)
            {
                Logger.logger("其它错误：" + ex.Message);
            }
        }
        static void CommnetWeiboViaMid(string LongMId, string comment)
        {
            try
            {
                NetDimension.Weibo.Entities.comment.Entity createComment = Weibo_tianqi.API.Entity.Comments.Create(LongMId, comment);
                Logger.logger("评论成功。Text:" + createComment.Text.Substring(0, (createComment.Text.Length < 10) ? createComment.Text.Length : 10));
            }
            catch (WeiboException ex)
            {
                Logger.logger("评论失败！错误码：" + ex.ErrorCode + " 原因: " + ex.Message);
            }
            catch (Exception ex)
            {
                Logger.logger("其它错误：" + ex.Message);
            }
        }
        static void SendMainCityPM25()
        {
            NetDimension.Weibo.Entities.status.Entity statusInfo = null;
            try
            {
                string weiboContent = realTimeMainCityStatus();
                statusInfo = Weibo_tianqi.API.Entity.Statuses.Update(weiboContent);
                Logger.logger("实时PM25。Text:" + statusInfo.Text.Substring(0, (statusInfo.Text.Length < 20) ? statusInfo.Text.Length : 20));
            }
            catch (WeiboException ex)
            {
                Logger.logger("发布失败！错误码：" + ex.ErrorCode + " 原因: " + ex.Message);
            }
            catch (Exception ex)
            {
                Logger.logger("其它错误：" + ex.Message);
            }
           
        }
        #endregion
      
        #region Comment
        static void LeaveMessage2PotentialCustomer()
        {
            int commentTimes = 0;
            bool method1 = true;
            //uint[] EnglishDaHao = { 2707563273, 1699451730, 1649977267, 1900887504, 2032414481, 2196649937, 1708242827, 1939417770, 2608436611, 2452849660, 2415967783, 2008644587, 2610990327, 2336769711, 1990139112, 1804522700, 1904271007, 2508522380, 2708561137, 1908763543, 2415965727, 1997631353, 1763254735, 2613101797, 2158792102, 2088963285, 2032663345, 2012028544, 2166360410, 2050018463, 1790424043, 2498747702, 2076719205, 1958372753, 2502349331, 1897256622, 2163511854, 2324920652, 2477938850, 2156978280, 2355755720, 2527825752 };
            uint[] EnglishDaHao = { 2707563273, 1699451730, 1649977267, 1900887504, 2032414481, 2196649937, 1708242827, 1939417770, 2608436611, 2452849660, 2415967783, 2008644587, 2610990327, 2336769711, 1990139112, 1804522700, 1904271007, 2508522380, 2708561137, 1908763543, 2415965727, 1997631353, 1763254735, 2613101797, 2158792102, 2088963285, 2032663345, 2012028544, 2166360410, 2050018463, 1790424043, 2498747702, 2076719205, 1958372753, 2502349331, 1897256622, 2163511854, 2324920652, 2477938850, 2156978280, 2355755720, 2527825752 };
            for (int idIndex = 0; idIndex < EnglishDaHao.Length; idIndex++)
            {
                try
                {
                    if (method1)
                    {
                        //method 1: 获取最近的5000个粉丝id号码
                        NetDimension.Weibo.Entities.user.IDCollection ids = Weibo_tianqi.API.Entity.Friendships.FollowerIDs(EnglishDaHao[idIndex].ToString(), "", 5000);
                        foreach (var id in ids.Users)
                        {
                            Logger.logger("ID:" + id.ToString());
                        }
                        foreach (var id in ids.Users)
                        {
                            NetDimension.Weibo.Entities.user.Entity usershow = Weibo_tianqi.API.Entity.Users.Show(id);
                            NetDimension.Weibo.Entities.comment.Entity createComment = Weibo_tianqi.API.Entity.Comments.Create(usershow.Status.ID, "@" + usershow.ScreenName + " 欢迎关注我的英语微博，及微信: YoudaoEnglish，二维码链接：http://weibo.com/2480531040/z9f5UfaTx");
                            commentTimes++;
                            Logger.logger("评论发送成功。ID:" + createComment.ID + ", Text:" + createComment.Text.Substring(0, 10));
                            Thread.Sleep(ro.Next(3000, 5000));
                        }
                    }
                    else
                    {
                        //method 2: //获取最活跃的200个粉丝账号的信息，包括id和name
                        string atSomebody = "";
                        IEnumerable<NetDimension.Weibo.Entities.user.Entity> activeIds = Weibo_tianqi.API.Entity.Friendships.FollowersInActive(EnglishDaHao[idIndex].ToString(), 200);
                        foreach (var activeId in activeIds)
                        {
                            if (atSomebody.Length < 103)
                            {
                                atSomebody += "@" + activeId.ScreenName;
                            }
                            else
                            {
                                Thread.Sleep(ro.Next(1000, 5000));
                                Logger.logger("提醒列表：" + atSomebody);
                                //NetDimension.Weibo.Entities.comment.Entity createComment = Sina.API.Entity.Comments.Create(Mid2Id("z9f5UfaTx").ToString(), atSomebody);
                                //logger("评论发送成功。ID:" + createComment.ID + ", Text:" + createComment.Text.Substring(0, 10));
                                atSomebody = "";
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.logger("评论发送异常：" + ex.Message);
                }
            }


        }
        static void LeaveMessageToKeywordCustomer(string keyword)
        {
            keyword = "pm2.5";
            string b = HttpWeb.getWeiboSearchHtmlViaHttpPOST("2487399871", "3_5bc278234d3121433a394e25d6b88b61a7c815b819", keyword);
            string[] mIds = GetShortMIdsFromWeiboCnSearchHtml(b, "id=\"M_(\\w{9})\"");

        }
        static void ReplyWeiboAtMe()
        {
            NetDimension.Weibo.Entities.status.Collection mentionsAtMe = Weibo_tianqi.API.Entity.Statuses.Mentions(null, null, 20, 1, 0, 0, 0);
            int choice = 2;

            //倒序
            List<NetDimension.Weibo.Entities.status.Entity> weibosAtMe = new List<NetDimension.Weibo.Entities.status.Entity>();
            foreach (var item in mentionsAtMe.Statuses)
            {
                weibosAtMe.Add(item);
            }
            weibosAtMe.Reverse();
            //foreach (var item in weibosAtMe)
            //{
            //    if (item.User.FollowersCount > 5000)
            //    {
            //        Logger.logger(item.User.Name + " " + item.CreatedAt + " " + item.User.FollowersCount.ToString());
            //    }
            //}
            foreach (var item in weibosAtMe)
            {
                NetDimension.Weibo.Entities.status.Entity statusInfo = null;
                NetDimension.Weibo.Entities.comment.Entity commentInfo = null;

                try
                {
                    //过滤已经发过的
                    if (AtMaxId >= Convert.ToInt64(item.ID))
                    {
                        continue;
                    }

                    if (CommentLimit > 24)
                    {
                        continue;
                    }

                    //非转发我的
                    if (item.RetweetedStatus != null && item.RetweetedStatus.User.ID != myUid)
                    {
                        continue;
                    }

                    choice = 2;
                    //纯转发
                    if (choice == 1)
                    {
                        //statusInfo = Weibo_tianqi.API.Entity.Statuses.Repost(item.ID, "", 0);
                    }
                    //纯评论
                    else if (choice == 2)
                    {
                        /*本吧吉祥物 
                        语叶丁香 乃青春无敌可爱活泼妹纸一枚，其岁尚小，理应蒙诸天神佛各路吧友照拂。然则有恶人若干，终日以戏香为乐，其心可诛。
                        吾妹尚幼而不涉世事，不堪戏弄而终日痛哭，郁郁无安。
                        吾欲怒而杀人，却念及妹之心情，而斩是岁之言语耳。
                        太史公有云：太上不辱先，其次不辱身，其次不辱理色，其次不辱辞令，其次诎体受辱，其次易服受辱，其次关木索、被棰楚受辱，其次剔毛发、婴金铁受辱，其次毁肌肤、断肢体受辱，最下腐刑极矣！尽数切肤之辱。
                        吾非尔等父母，亦非尔等司长，不可行之以刑。然则世事皆由常，不可违其道，兹定规矩若干，合于天道，得于地势，顺于人心。
                        无故调戏者，斩；
                        辱及家人者，斩；
                        污言秽语者，斩；
                        欺凌逼迫者，斩；
                        聚众跟风者，斩；
                        涉及国政者，斩。
                        天地仁慈，万物皆得其生养。然则佛有怒目金刚，不循规矩者，吾等将代天地而伐。
                        钦此。。
                        白话文翻译：
                        再有调戏我家妮子的，统统删帖，轰杀至渣。屡教不改又或污言秽语者，封！封！封！*/
                        string replyContent = string.Empty;
                        if (item.Text.Contains("@查天气"))
                        {
                            List<string> replyList = new List<string>();
                            //replyList.Add("，阿弥陀佛，施[猪头]用情不专[花心]，爱了一个不知足，又爱上另一个[不要]……小神泄漏天机，罪过罪过[orz]");
                            replyList.Add("，阿弥陀佛，施[猪头]用情不专[花心]，爱了一个不知足，又爱上另一个[不要]……");
                            //replyList.Add("，不要把神仙和机器人相提并论！");
                            //replyList.Add("，你这是什么意思？？？[鄙视]");
                            //replyList.Add("，心诚则灵，心不诚则不灵。");
                            //replyList.Add("，你有权保持沉默，但你所说的一切都将成为呈堂证供。");
                            replyContent = replyList[ro.Next(replyList.Count)];
                        }
                        else
                        {
                            replyContent = getWeatherAndPM25(item.User.Province, item.User.City, item.Text);
                        }
                        commentInfo = Weibo_tianqi.API.Entity.Comments.Create(item.ID, "@" + item.User.Name + replyContent);
                        CommentLimit++;
                    }
                    //纯文本发微博
                    else if (choice == 3)
                    {
                        statusInfo = Weibo_tianqi.API.Entity.Statuses.Update("");
                    }
                    //带图片发送微博
                    else
                    {
                        //用有权限的接口
                        if (false && Regex.IsMatch(AppKey, "82966982|2323547071", RegexOptions.IgnoreCase))
                        {
                            statusInfo = Weibo_tianqi.API.Entity.Statuses.UploadUrlText("text", "http://");
                        }
                        //下载并加水印
                        else
                        {
                            string DownloadedFile = Picture.DownloadPicture("http://www.abc.com/a.jpg");
                            if (false && AutoWaterMark && DownloadedFile.Contains(".jpg"))
                            {
                                string FileWithWater = WaterMark.AddImageSignPic(DownloadedFile, waterMarkFile, 9, 100, 6);
                                DownloadedFile = FileWithWater;
                            }
                            if (DownloadedFile != "")
                            {
                                byte[] OpenedPicture = Picture.OpenFile(DownloadedFile);
                                if (OpenedPicture != null)
                                {
                                    statusInfo = Weibo_tianqi.API.Entity.Statuses.Upload("text", OpenedPicture);
                                }
                            }
                            else
                            {
                                throw new Exception("DownloadedFile is empty");
                            }
                        }
                    }


                    if (statusInfo != null)
                    {
                        Logger.logger("发布成功。Text:" + statusInfo.Text.Substring(0, (statusInfo.Text.Length < 20) ? statusInfo.Text.Length : 20));
                    }
                    if (commentInfo != null)
                    {
                        Logger.logger("评论成功。Text:" + commentInfo.Text.Substring(0, (commentInfo.Text.Length < 20) ? commentInfo.Text.Length : 20));
                    }
 
                    Thread.Sleep(ro.Next(10000, 30000));
                }
                catch (WeiboException ex)
                {
                    //记录mid
                    XML.WriteExt("MID", "AtMaxId", item.ID);
                    AtMaxId = Convert.ToInt64(item.ID);
                    Thread.Sleep(ro.Next(10000, 30000));
                    Logger.logger("发布失败！错误码：" + ex.ErrorCode + " 原因:" + ex.Message + " Item：" + item);

                    //将评论错误打印出来
                    if (ex.ErrorCode == "20012" && commentInfo != null)
                    {
                        Logger.logger("TEXT:" + commentInfo.Text.ToString() + " LENGTH:" + commentInfo.Text.Length);
                    }
                }
                catch (Exception ex)
                {
                    Logger.logger("其它错误：" + ex.Message);
                }
            }
        }
        static void RandomReplyWeiboByKeyword(string keyword)
        {
            Logger.logger("开始自动评论。");
            string b = HttpWeb.getWeiboSearchHtmlViaHttpPOST("2487399871", "3_5bc278234d3121433a394e25d6b88b61a7c815b819", keyword);
            string[] shortMIds = GetShortMIdsFromWeiboCnSearchHtml(b, "id=\"M_(\\w{9})\"");
            if (shortMIds.Length == 0)
            {
                Logger.logger("获得的评论ID列表为0个，gsid可能已生效!？");
                validGsid = false;
                return;
            }
            var Longids = Weibo_tianqi.API.Entity.Statuses.QueryID(1, false, true, shortMIds);

            foreach (var longMid in Longids)
            {
                NetDimension.Weibo.Entities.comment.Entity commentInfo = null;
                try
                {
                    //过滤已经发过的，长度不为16位的
                    if (SearchMaxId >= Convert.ToInt64(longMid) || !Regex.IsMatch(longMid, "\\d{16}"))
                    {
                        continue;
                    }
                    if (CommentLimit > 24)
                    {
                        continue;
                    }
                    NetDimension.Weibo.Entities.status.Entity statusInfo = Weibo_tianqi.API.Entity.Statuses.Show(longMid);

                    //转发的不回复
                    if (statusInfo.RetweetedStatus != null)
                    {
                        continue;
                    }
                    //不回复的 数丝数超100万 或小于100 ，或同行 
                    if (statusInfo.User.FollowersCount > 10001234 || statusInfo.User.FollowersCount < 500
                        || Regex.IsMatch(statusInfo.User.Name, "天气|气象|新浪|公安|网警")
                        || Regex.IsMatch(statusInfo.Text, "@查天气|@天气神|@天气通|@中国天气网|@墨迹天气|℃"))
                    {
                        continue;
                    }

                    //过滤自己的
                    if (statusInfo.User.ID == MyUserInfo.ID)
                    {
                        continue;
                    }

                    string weatherID = Sqlite.SearchWeatherIDByPlaceID(statusInfo.User.Province, statusInfo.User.City);
                    if (string.IsNullOrEmpty(weatherID))
                    {
                        //commentInfo = Weibo_tianqi.API.Entity.Comments.Create(statusInfo.ID, "@" + statusInfo.User.Name + " ，您好，我们发现您在微博中提到\"天气\"，天界神仙政府驻新浪微博大使@天气神 已经开通了微博，您可以关注TA了解TA的最新动态。");
                    }
                    else
                    {
                        string weiboContent = getWeatherAndPM25(statusInfo.User.Province, statusInfo.User.City, statusInfo.Text); //函数来生成,地址作参数
                        if (weiboContent.Contains("神仙都找不到你"))
                        {
                            continue;
                        }
                        commentInfo = Weibo_tianqi.API.Entity.Comments.Create(longMid, "@" + statusInfo.User.Name + weiboContent);
                    }
                    CommentLimit++;

                    if (commentInfo != null)
                    {
                        Logger.logger("评论成功。Text:" + commentInfo.Text.Substring(0, (commentInfo.Text.Length < 20) ? commentInfo.Text.Length : 20));
                    }
                    //记录mid
                    XML.WriteExt("MID", "SearchMaxId", longMid);
                    SearchMaxId = Convert.ToInt64(longMid);

                }
                catch (WeiboException ex)
                {
                    if (Regex.IsMatch(ex.ErrorCode, "20507|20031|20016", RegexOptions.IgnoreCase))
                    {
                        //FollowLimitFreq++;
                        //Logger.logger("评论频率:" + FollowLimitFreq.ToString());
                        //Logger.logger("结束自动评论。" + ex.ErrorCode + " 原因:" + ex.Message);
                        Logger.logger("评论失败！错误码：" + ex.ErrorCode + " 原因:" + ex.Message + " Item：" + longMid);
                        return;
                    }
                    Logger.logger("评论失败！错误码：" + ex.ErrorCode + " 原因:" + ex.Message + " Item：" + longMid);

                    //将评论错误打印出来
                    if (ex.ErrorCode == "20012" && commentInfo != null)
                    {
                        Logger.logger("TEXT:" + commentInfo.Text.ToString() + " LENGTH:" + commentInfo.Text.Length);
                    }
                }
                catch (Exception ex)
                {
                    Logger.logger("其它错误：" + ex.Message);
                }
                Thread.Sleep(ro.Next(10000, 20000));
            }

            Logger.logger("结束自动评论。");
        }
        #endregion

        #region Fans
        static void FollowFans_old()
        {
            string friends;

            friends = "3073482613,1345727452";
            string[] splitFriend = friends.Split(',');

            int waitTime = 5000;
            int followCount = 0;

            for (int i = 0; i < splitFriend.Length; i++)
            {
                if (followCount <= 158)
                {
                    try
                    {
                        Thread.Sleep(ro.Next(15000, 30000));
                        var relation = Weibo_tianqi.API.Entity.Friendships.Show(myUid, "", splitFriend[i], "");
                        if (!relation.Source.Following && !Regex.IsMatch(relation.Target.ScreenName, "购物|返利|兼职|招聘|营销|团购|精选", RegexOptions.IgnoreCase))
                        {
                            var entity = Weibo_tianqi.API.Entity.Friendships.Create(splitFriend[i], "");
                            Logger.logger("关注了：" + i.ToString() + " / " + splitFriend.Length.ToString() + " " + splitFriend[i] + "|" + entity.Name);
                            followCount++;
                        }
                        else
                        {
                            Logger.logger("不关注：" + i.ToString() + " / " + splitFriend.Length.ToString() + " " + splitFriend[i] + "|" + relation.Target.ScreenName);
                        }

                    }
                    catch (WeiboException ex)
                    {
                        Logger.logger("weibo错误：" + ex.Message);
                        if (ex.ErrorCode == "21332")
                        {
                            GetAccessToken();
                            Weibo_tianqi = new Client(oauth_tianqi);
                            string uid2 = Weibo_tianqi.API.Entity.Account.GetUID();
                            var entity_userInfo = Weibo_tianqi.API.Entity.Users.Show(myUid);
                            Logger.logger("uid：" + uid2 + ", 昵称：" + entity_userInfo.ScreenName);
                        }
                        Logger.logger("等待：" + waitTime.ToString());
                        Thread.Sleep(waitTime);
                        waitTime += 5000;
                    }
                    catch (Exception ex)
                    {
                        Logger.logger("other 错误：" + ex.Message);
                    }
                }
                else
                {
                    Logger.logger("当前关注" + followCount.ToString());
                    break;
                }
            }
            Console.ReadKey(); //防止程序自行退出
        }
        static void FollowQunUser()
        {
            Logger.logger("开始关注");
            if (FollowLimit)
            {
                Logger.logger("上次执行错误，等待明日再进行。");
                return;
            }
            string[] qunlist = "112135|141852|150536|166591|173898|181008|200852|205347|216016|228249|240584|243676|246925|257968|265032|267692|271887|276479|277515|280770|297490|322998|411875|427099|432608|539595|557213|581630|597194|646262|648476|678128|685170|714603|762352|789246|875330|926119|942483|998548".Split('|');
            string qunid = qunlist[ro.Next(qunlist.Length)];

            string a = HttpWeb.getWeiboQunHtmlViaHttpGET("2487399871", "3_5bc278234d3121433a394e25d6b88b61a7c815b819", qunid);
            string[] splitFriend = GetContentsFromWeiboCnQunHtml(a, "/(\\d{6,10})/qun\\?");
            Logger.logger("获得" + splitFriend.Length + "个名单。In Group:" + qunid);
            int followCount = 0;
            for (int i = 0; i < splitFriend.Length; i++)
            {
                if (followCount <= 240)
                {
                    try
                    {
                        Thread.Sleep(ro.Next(5000, 15000));
                        var relation = Weibo_tianqi.API.Entity.Users.Show(splitFriend[i]);
                        if (relation.Following)
                        {
                            continue;
                        }
                        if (relation.FollowersCount < relation.FriendsCount)
                        {
                            var entity = Weibo_tianqi.API.Entity.Friendships.Create(splitFriend[i], "");
                            Logger.logger("关注了：" + i.ToString() + " - " + splitFriend.Length.ToString() + " " + splitFriend[i] + "|" + entity.Name);
                            followCount++;
                        }
                        else if (!Regex.IsMatch(relation.ScreenName, "返|兼|聘|销|购|潮", RegexOptions.IgnoreCase)
                                && relation.FollowersCount < 15000
                                && (relation.FollowersCount < relation.FriendsCount + 1000)
                            )
                        {
                            var entity = Weibo_tianqi.API.Entity.Friendships.Create(splitFriend[i], "");
                            Logger.logger("关注了：" + i.ToString() + " / " + splitFriend.Length.ToString() + " " + splitFriend[i] + "|" + entity.Name);
                            followCount++;
                        }

                    }
                    catch (WeiboException ex)
                    {
                        FollowLimit = true;
                        Logger.logger("微博异常：Code:" + ex.ErrorCode + ", " + ex.Message);
                        return;
                    }
                    catch (Exception ex)
                    {
                        Logger.logger("other 错误：" + ex.Message);
                    }
                }
                else
                {
                    Logger.logger("当前关注" + followCount.ToString());
                    break;
                }
            }
            Logger.logger("结束关注.");
        }
        #endregion

        #region Tray
        //还原窗体
        private void notifyIcon1_DoubleClick(object sender, EventArgs e)
        {
            //判断是否已经最小化于托盘 
            if (WindowState == FormWindowState.Minimized)
            {
                //还原窗体显示 
                WindowState = FormWindowState.Normal;
                //激活窗体并给予它焦点 
                this.Activate();
                //任务栏区显示图标 
                this.ShowInTaskbar = true;
                //托盘区图标隐藏 
                notifyicon.Visible = false;
            }
        }

        //隐藏任务栏图标、显示托盘图标
        private void Form1_SizeChanged(object sender, EventArgs e)
        {
            //判断是否选择的是最小化按钮 
            if (WindowState == FormWindowState.Minimized)
            {
                //托盘显示图标等于托盘图标对象 
                //注意notifyIcon1是控件的名字而不是对象的名字 
                //notifyIcon1.Icon = ico;
                //隐藏任务栏区图标 
                this.ShowInTaskbar = false;
                //图标显示在托盘区 
                notifyicon.Visible = true;
            }
        }

        //打开日志
        private void openLoggerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DateTime currentTime = DateTime.Now;
            string str = Directory.GetCurrentDirectory();
            string fname = currentTime.ToString("yyyy") + currentTime.ToString("MM") + ".log";
            string logfile = str + "\\" + fname;
            Process.Start("notepad.exe", logfile);
        }
        //转到微博
        private void goToWeiboToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string myWeibo = "http://weibo.com/" + myUid;
            Process.Start(myWeibo);
        }
        //退出程序
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Process.GetCurrentProcess().Kill();
        }
        #endregion

        #region Weibo.cn
        public static string[] GetShortMIdsFromWeiboCnSearchHtml(string html, string idPattern)
        {
            //string midPattern = "id=\"M_(\\w{9})\"";
            List<string> shortMIds = new List<string>();

            string[] weibos = html.Split(new string[] { "<div class=\"s\"></div>" }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < weibos.Length; i++)
            {
                MatchCollection m = Regex.Matches(weibos[i], idPattern);
                foreach (Match item in m)
                {                
                    //string longId = MidToId.ShortMid2LongMId(item.Groups[1].Value.ToString());
                    //if (!longMIds.Contains(longId))
                    //    longMIds.Add(longId);
                    string shortId = item.Groups[1].Value.ToString();
                    if (!shortMIds.Contains(shortId))
                        shortMIds.Add(shortId);
                }
            }
            shortMIds.Sort(); //排序
            //longMIds.Reverse(); //反转

            return shortMIds.ToArray();
        }
        public static string[] GetContentsFromWeiboCnQunHtml(string html, string idPattern)
        {
            //string midPattern = "id=\"M_(\\w{9})\"";
            List<string> mIds = new List<string>();

            string[] weibos = html.Split(new string[] { "<div class=\"s\"></div>" }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < weibos.Length; i++)
            {
                if (Regex.IsMatch(weibos[i], "淘宝|兼职|元|笑话"))
                {
                    continue;
                }
                MatchCollection m = Regex.Matches(weibos[i], idPattern);
                foreach (Match item in m)
                {
                    string id = item.Groups[1].Value.ToString();
                    if (!mIds.Contains(id) && Regex.IsMatch(weibos[i], "互粉"))
                        mIds.Add(id);
                }
            }
            return mIds.ToArray();
        }
        public static void testWeiboCn()
        {
            string a = HttpWeb.getWeiboQunHtmlViaHttpGET("2487399871", "3_5bc278234d3121433a394e25d6b88b61a7c815b819", "228249");
            string[] uIds = GetContentsFromWeiboCnQunHtml(a, "/(\\d{6,10})/qun\\?");

            string b = HttpWeb.getWeiboSearchHtmlViaHttpPOST("2487399871", "3_5bc278234d3121433a394e25d6b88b61a7c815b819", "天气");
            string[] mIds = GetShortMIdsFromWeiboCnSearchHtml(b, "id=\"M_(\\w{9})\"");
        }
        #endregion

        #region PM2.5
        /*
            pm2.5浓度 （单位：μg/m³） 空气污染指数 污染级别 健康建议
            0-35 0-50 优 各类人群可以正常活动 
            36-75 50-100 良 极少数异常敏感人群应减少户外活动 
            76-115 100-150 轻度污染 儿童、老年人及心脏病或呼吸系统疾病患者应减少长时间或者高强度户外锻炼 
            116-150 150-200 中度污染 儿童、老年人及心脏病或呼吸系统疾病患者应减少长时间或者高强度户外锻炼，一般人群适量减少户外运动 
            151-250  200-300 重度污染 儿童、老年人及心脏病或呼吸系统疾病患者应停留在室内，停止户外运动，一般人群减少户外运动 
            大于250 大于300 严重污染 儿童、老年人及心脏病或呼吸系统疾病患者应停留在室内，避免体力消耗，一般人群应避免户外运动 
        */
        public void getWeiboCityList()
        {
            Dictionary<string, string> provinces = Weibo_tianqi.API.Entity.Common.GetProvince("001");
            foreach (KeyValuePair<string, string> provincekvp in provinces)
            {
                //Logger.logger("Key = " + kvp.Key + ", Value = " +kvp.Value);
                string provinceId = provincekvp.Key.Substring(3, 3);
                Dictionary<string, string> cities = Weibo_tianqi.API.Entity.Common.GetCity(provincekvp.Key);
                Thread.Sleep(500);
                foreach (KeyValuePair<string, string> kvpcity in cities)
                {
                    string cityId = kvpcity.Key.Substring(6, 3);
                    Logger.logger(Convert.ToInt32(provinceId).ToString() + ", " + provincekvp.Value + ", " + Convert.ToInt32(cityId).ToString() + ", " + kvpcity.Value);
                }
                Logger.logger(Convert.ToInt32(provinceId).ToString() + ", " + provincekvp.Value + ", 100, 不限");
            }
        }
        public static Dictionary<string, string> GetPM25FromAqiCnInfo()
        {
            Dictionary<string, string> pm25List = new Dictionary<string, string>();
            string requestURL = "http://www.aqicn.info/?city=all";
            string referer = requestURL;
            
            string pm25Pattern = "<span>(.+?)\\</small>\\:</span><span\\sclass='aqival'>(\\d+)</span>";
            string html = HttpWeb.HttpGETRequest(requestURL, 60000, referer, string.Empty, new CookieContainer());

            string[] cityList = html.Split(new string[] { "<div class='citylist'>" }, StringSplitOptions.RemoveEmptyEntries);
            bool chinaCityEnough = false;
            for (int i = 0; i < cityList.Length; i++)
            {
                MatchCollection m = Regex.Matches(cityList[i], pm25Pattern);
                foreach (Match item in m)
                {
                    if (item.Groups[1].Value.Contains("昌平定陵") || item.Groups[1].Value.Contains("Changping Dingling"))
                    {
                        chinaCityEnough = true;
                        break;
                    }
                    if (!pm25List.ContainsKey(item.Groups[1].Value))
                    {
                        pm25List.Add(item.Groups[1].Value, item.Groups[2].Value);
                    }
                }
                if (chinaCityEnough)
                {
                    break;
                }
            }
            if (pm25List.Count == 0)
            {
                throw new Exception("获得城市PM2.5数据为0个！");
            }
            return pm25List;
        }
        public static void UpdatePM25ToDataBase()
        {
            SyncPM25ToDB = false;
            int trytime = 0;
            while (trytime < 3)
            {
                try
                {
                    Logger.logger("开始第" + (trytime + 1).ToString() + "次同步PM2.5数据");
                    Dictionary<string, string> pm24DataList = GetPM25FromAqiCnInfo();
                    Dictionary<int, string> indexAndCity = Sqlite.SearchIndexAndCity();
                    foreach (var dbItem in indexAndCity)
                    {
                        foreach (var pmItem in pm24DataList)
                        {
                            if (pmItem.Key.Contains(dbItem.Value))
                            {
                                string updatesql = "UPDATE \"Weather\" SET \"PM25\" = " + pmItem.Value + " WHERE \"Index\" = " + dbItem.Key.ToString() + ";";
                                bool update = Sqlite.UpdatePM25toDB(updatesql);
                                Thread.Sleep(1);
                                break;
                            }
                        }
                    }
                    SyncPM25ToDB = true;
                    break;
                }
                catch (Exception)
                {
                    trytime++;
                }
            }
            if (!SyncPM25ToDB)
            {
                Logger.logger("同步PM2.5数据失败。");
            }
            else
            {
                Logger.logger("同步PM2.5数据成功。");
            }
        }
        public static string airQualityLevel(int value, bool comment)
        {
            string level = string.Empty;
            if (value <= 50)
            {
                level = "优"+ "(" + value.ToString() + ")";
                if (comment) {level += "。WAKAO，这么低，相比其他地方，你真是在天堂！！！";}
                
            }
            else if (value <= 100)
            {
                level = "良"+ "(" + value.ToString() + ")";
                if (comment) {level += "。还不错！";}
            }
            else if (value <= 150)
            {
                level = "轻微污染"+ "(" + value.ToString() + ")";
                if (comment) { level += "。一般般。"; }
            }
            else if (value <= 200)
            {
                level = "轻度污染"+ "(" + value.ToString() + ")";
                if (comment) {}
            }
            else if (value <= 250)
            {
                level = "中度污染"+ "(" + value.ToString() + ")";
                if (comment) { }
            }
            else if (value <= 300)
            {
                level = "中度重污染"+ "(" + value.ToString() + ")";
                if (comment) { level += "。出门戴口罩，回家清鼻腔！"; }
            }
            else
            {
                level = "重污染"+ "(" + value.ToString() + ")";
                level += " “咳咳 咳咳 咳咳……”";
                if (comment) { level += "。出门戴口罩，回家清鼻腔！"; }
            }

            return level;
        }
        public static string realTimeMainCityStatus()
        {
            bool getLevel = false;
            string[] cityList = "北京|上海|广州|深圳|成都|南京|天津|重庆|西安|杭州|武汉|厦门".Split('|');
            string weiboContent = "#实时空气质量# ";
            for (int i = 0; i < cityList.Length; i++)
            {
                int cityPm25Value = Sqlite.SearchPM25ByCityName(cityList[i]);
                if (cityPm25Value > 0 && (i != cityList.Length - 1))
                {
                    getLevel = true;
                    weiboContent += cityList[i] + "：" + airQualityLevel(cityPm25Value, false) + " ";
                }
            }
            return (getLevel) ? weiboContent : string.Empty;
        }
        public static string getWeatherAndPM25(string provinceId, string cityId,string weiboText)
        {
            string weatherContent = string.Empty;
            string pm25Content = string.Empty;

            //通过内容找地址
            string weatherID = Sqlite.getWeatherIdByWeiboText(weiboText);
            if (string.IsNullOrEmpty(weatherID))
            {
                //否则通过资料找地址
                weatherID = Sqlite.SearchWeatherIDByPlaceID(provinceId, cityId);
            }

            //还找不到，就算了
            if (string.IsNullOrEmpty(weatherID))
            {
                return "，你隐藏得太深了，神仙都找不到你。。。。。";
            }

            weatherContent = GetWeatherForecaset_SixDays(weatherID); //函数来生成,地址作参数
            int pm25value = Sqlite.SearchPM25ByPlaceID(weatherID);
            if (pm25value > 0)
            {
                pm25Content = "悟空取得的【空气污染指数】为：" + airQualityLevel(pm25value, false);
            }
            Thread.Sleep(ro.Next(1000, 3000));
            return weatherContent + pm25Content;
        }
        #endregion

        #region Weather
        static void GetWeatherInfoNodeFromXML()
        {

            try
            {
                string country = "china";

                XmlDocument countryXmlDoc = HttpWeb.getWeatherPlaceViaHttpGet(country);
                XmlNodeList provinceNodes = countryXmlDoc.SelectSingleNode(country).ChildNodes;
                foreach (XmlNode provinceNode in provinceNodes)
                {
                    try
                    {
                        XmlElement provinceElement = (XmlElement)provinceNode;
                        string provincePyName = provinceElement.GetAttribute("pyName");
                        string provinceCnName = provinceElement.GetAttribute("quName");
                        //string provinceUrl = provinceElement.GetAttribute("cityname");

                        if (Regex.IsMatch(provinceCnName, "西沙|南沙|钓鱼岛", RegexOptions.IgnoreCase))
                        {
                            continue;
                        }
                        else if (Regex.IsMatch(provinceCnName, "香港|澳门", RegexOptions.IgnoreCase))
                        {
                            continue;
                        }
                        else
                        {
                            XmlDocument provinceXmlDoc = HttpWeb.getWeatherPlaceViaHttpGet(provincePyName);
                            XmlNodeList cityNodes = provinceXmlDoc.SelectSingleNode(provincePyName).ChildNodes;
                            foreach (XmlNode cityNode in cityNodes)
                            {
                                try
                                {
                                    XmlElement cityElement = (XmlElement)cityNode;
                                    string centerName = cityElement.GetAttribute("centername");
                                    string cityPyName = cityElement.GetAttribute("pyName");
                                    string cityName = cityElement.GetAttribute("cityname");
                                    string cityUrl = cityElement.GetAttribute("url");

                                    cutLastXianShi(cityName, cityUrl);
                                    //
                                    XmlDocument districtXmlDoc = HttpWeb.getWeatherPlaceViaHttpGet(cityPyName);
                                    XmlNodeList districtNodes = districtXmlDoc.SelectSingleNode(cityPyName).ChildNodes;
                                    foreach (XmlNode districtNode in districtNodes)
                                    {
                                        XmlElement districtElement = (XmlElement)districtNode;
                                        string districtName = districtElement.GetAttribute("centername");
                                        string districtPyName = districtElement.GetAttribute("pyName");
                                        string districtUrl = districtElement.GetAttribute("url");
                                        cutLastXianShi(districtName, districtUrl);
                                    }
                                    Thread.Sleep(1);
                                }
                                catch (Exception ex)
                                {
                                    string error = "DEBUG " + ex.Message;
                                }
                                //Logger.logger("WeatherCityList.Add(\"" + centerName + "\", \"" + cityUrl + "\")");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string error = "DEBUG " + ex.Message;
                        //Logger.logger("DEBUG " + ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.logger("DEBUG " + ex.Message);
            }

        }
        static void cutLastXianShi(string placeName, string placeWeatherId)
        {
            #region place
            List<string> placeList = new List<string>();
            placeList.Add("101010100");
            placeList.Add("101020100");
            placeList.Add("101030100");
            placeList.Add("101040100");
            placeList.Add("101050101");
            placeList.Add("101050201");
            placeList.Add("101050301");
            placeList.Add("101050401");
            placeList.Add("101050501");
            placeList.Add("101050601");
            placeList.Add("101050701");
            placeList.Add("101081101");
            placeList.Add("101050801");
            placeList.Add("101050901");
            placeList.Add("101051002");
            placeList.Add("101051101");
            placeList.Add("101051201");
            placeList.Add("101051301");
            placeList.Add("101060101");
            placeList.Add("101060201");
            placeList.Add("101060312");
            placeList.Add("101060401");
            placeList.Add("101060501");
            placeList.Add("101060601");
            placeList.Add("101060701");
            placeList.Add("101060801");
            placeList.Add("101060901");
            placeList.Add("101070101");
            placeList.Add("101070201");
            placeList.Add("101070301");
            placeList.Add("101070401");
            placeList.Add("101070501");
            placeList.Add("101070601");
            placeList.Add("101070701");
            placeList.Add("101070801");
            placeList.Add("101070901");
            placeList.Add("101071001");
            placeList.Add("101071101");
            placeList.Add("101071201");
            placeList.Add("101071301");
            placeList.Add("101071401");
            placeList.Add("101080101");
            placeList.Add("101080201");
            placeList.Add("101080301");
            placeList.Add("101080401");
            placeList.Add("101080501");
            placeList.Add("101080601");
            placeList.Add("101080701");
            placeList.Add("101080801");
            placeList.Add("101080901");
            placeList.Add("101081000");
            placeList.Add("101081201");
            placeList.Add("101090101");
            placeList.Add("101090201");
            placeList.Add("101090301");
            placeList.Add("101090402");
            placeList.Add("101090501");
            placeList.Add("101090601");
            placeList.Add("101090701");
            placeList.Add("101090801");
            placeList.Add("101090901");
            placeList.Add("101091001");
            placeList.Add("101091101");
            placeList.Add("101100101");
            placeList.Add("101100201");
            placeList.Add("101100301");
            placeList.Add("101100401");
            placeList.Add("101100501");
            placeList.Add("101100601");
            placeList.Add("101100701");
            placeList.Add("101100801");
            placeList.Add("101100901");
            placeList.Add("101101001");
            placeList.Add("101101100");
            placeList.Add("101110101");
            placeList.Add("101110200");
            placeList.Add("101110300");
            placeList.Add("101110401");
            placeList.Add("101110501");
            placeList.Add("101110601");
            placeList.Add("101110701");
            placeList.Add("101110801");
            placeList.Add("101110901");
            placeList.Add("101111001");
            placeList.Add("101120101");
            placeList.Add("101120201");
            placeList.Add("101120301");
            placeList.Add("101120401");
            placeList.Add("101120501");
            placeList.Add("101120601");
            placeList.Add("101120701");
            placeList.Add("101120801");
            placeList.Add("101120901");
            placeList.Add("101121001");
            placeList.Add("101121101");
            placeList.Add("101121201");
            placeList.Add("101121301");
            placeList.Add("101121401");
            placeList.Add("101121501");
            placeList.Add("101121601");
            placeList.Add("101121701");
            placeList.Add("101130101");
            placeList.Add("101130201");
            placeList.Add("101130301");
            placeList.Add("101130401");
            placeList.Add("101130501");
            placeList.Add("101130601");
            placeList.Add("101130801");
            placeList.Add("101130901");
            placeList.Add("101131001");
            placeList.Add("101131101");
            placeList.Add("101131201");
            placeList.Add("101131301");
            placeList.Add("101131401");
            placeList.Add("101131601");
            placeList.Add("101140101");
            placeList.Add("101140201");
            placeList.Add("101140301");
            placeList.Add("101140401");
            placeList.Add("101140501");
            placeList.Add("101140601");
            placeList.Add("101140701");
            placeList.Add("101150101");
            placeList.Add("101150201");
            placeList.Add("101150301");
            placeList.Add("101150401");
            placeList.Add("101150501");
            placeList.Add("101150601");
            placeList.Add("101150701");
            placeList.Add("101150801");
            placeList.Add("101160101");
            placeList.Add("101160201");
            placeList.Add("101160301");
            placeList.Add("101160401");
            placeList.Add("101160501");
            placeList.Add("101160601");
            placeList.Add("101160701");
            placeList.Add("101160801");
            placeList.Add("101160901");
            placeList.Add("101161101");
            placeList.Add("101161201");
            placeList.Add("101161301");
            placeList.Add("101161401");
            placeList.Add("101170101");
            placeList.Add("101170201");
            placeList.Add("101170301");
            placeList.Add("101170401");
            placeList.Add("101170501");
            placeList.Add("101180101");
            placeList.Add("101180201");
            placeList.Add("101180301");
            placeList.Add("101180401");
            placeList.Add("101180501");
            placeList.Add("101180601");
            placeList.Add("101180701");
            placeList.Add("101180801");
            placeList.Add("101180901");
            placeList.Add("101181001");
            placeList.Add("101181101");
            placeList.Add("101181201");
            placeList.Add("101181301");
            placeList.Add("101181401");
            placeList.Add("101181501");
            placeList.Add("101181601");
            placeList.Add("101181701");
            placeList.Add("101181801");
            placeList.Add("101190101");
            placeList.Add("101190201");
            placeList.Add("101190301");
            placeList.Add("101190401");
            placeList.Add("101190501");
            placeList.Add("101190601");
            placeList.Add("101190701");
            placeList.Add("101190801");
            placeList.Add("101190901");
            placeList.Add("101191001");
            placeList.Add("101191101");
            placeList.Add("101191201");
            placeList.Add("101191301");
            placeList.Add("101200101");
            placeList.Add("101200201");
            placeList.Add("101200301");
            placeList.Add("101200401");
            placeList.Add("101200501");
            placeList.Add("101200601");
            placeList.Add("101200701");
            placeList.Add("101200801");
            placeList.Add("101200901");
            placeList.Add("101201001");
            placeList.Add("101201101");
            placeList.Add("101201201");
            placeList.Add("101201301");
            placeList.Add("101201401");
            placeList.Add("101201501");
            placeList.Add("101201601");
            placeList.Add("101201701");
            placeList.Add("101210101");
            placeList.Add("101210201");
            placeList.Add("101210301");
            placeList.Add("101210401");
            placeList.Add("101210501");
            placeList.Add("101210601");
            placeList.Add("101210701");
            placeList.Add("101210801");
            placeList.Add("101210901");
            placeList.Add("101211001");
            placeList.Add("101211101");
            placeList.Add("101220101");
            placeList.Add("101220201");
            placeList.Add("101220301");
            placeList.Add("101220401");
            placeList.Add("101220501");
            placeList.Add("101220601");
            placeList.Add("101220701");
            placeList.Add("101220801");
            placeList.Add("101220901");
            placeList.Add("101221001");
            placeList.Add("101221101");
            placeList.Add("101221201");
            placeList.Add("101221301");
            placeList.Add("101221401");
            placeList.Add("101221501");
            placeList.Add("101221601");
            placeList.Add("101221701");
            placeList.Add("101230101");
            placeList.Add("101230201");
            placeList.Add("101230301");
            placeList.Add("101230401");
            placeList.Add("101230501");
            placeList.Add("101230601");
            placeList.Add("101230701");
            placeList.Add("101230801");
            placeList.Add("101230901");
            placeList.Add("101240101");
            placeList.Add("101240201");
            placeList.Add("101240301");
            placeList.Add("101240401");
            placeList.Add("101240501");
            placeList.Add("101240601");
            placeList.Add("101240701");
            placeList.Add("101240801");
            placeList.Add("101240901");
            placeList.Add("101241001");
            placeList.Add("101241101");
            placeList.Add("101250101");
            placeList.Add("101250201");
            placeList.Add("101250301");
            placeList.Add("101250401");
            placeList.Add("101250501");
            placeList.Add("101250601");
            placeList.Add("101250700");
            placeList.Add("101250703");
            placeList.Add("101250801");
            placeList.Add("101250901");
            placeList.Add("101251001");
            placeList.Add("101251101");
            placeList.Add("101251201");
            placeList.Add("101251401");
            placeList.Add("101251501");
            placeList.Add("101260101");
            placeList.Add("101260201");
            placeList.Add("101260301");
            placeList.Add("101260401");
            placeList.Add("101260501");
            placeList.Add("101260601");
            placeList.Add("101260701");
            placeList.Add("101260801");
            placeList.Add("101260901");
            placeList.Add("101270101");
            placeList.Add("101270201");
            placeList.Add("101270301");
            placeList.Add("101270401");
            placeList.Add("101270501");
            placeList.Add("101270601");
            placeList.Add("101270701");
            placeList.Add("101270801");
            placeList.Add("101270901");
            placeList.Add("101271001");
            placeList.Add("101271101");
            placeList.Add("101271201");
            placeList.Add("101271301");
            placeList.Add("101271401");
            placeList.Add("101271501");
            placeList.Add("101271601");
            placeList.Add("101271701");
            placeList.Add("101271801");
            placeList.Add("101271901");
            placeList.Add("101272001");
            placeList.Add("101272101");
            placeList.Add("101280101");
            placeList.Add("101280201");
            placeList.Add("101280301");
            placeList.Add("101280401");
            placeList.Add("101280501");
            placeList.Add("101280601");
            placeList.Add("101280701");
            placeList.Add("101280800");
            placeList.Add("101280901");
            placeList.Add("101281001");
            placeList.Add("101281101");
            placeList.Add("101281201");
            placeList.Add("101281301");
            placeList.Add("101281401");
            placeList.Add("101281501");
            placeList.Add("101281601");
            placeList.Add("101281701");
            placeList.Add("101281801");
            placeList.Add("101281901");
            placeList.Add("101282001");
            placeList.Add("101282101");
            placeList.Add("101290101");
            placeList.Add("101290201");
            placeList.Add("101290301");
            placeList.Add("101290401");
            placeList.Add("101290501");
            placeList.Add("101290601");
            placeList.Add("101290701");
            placeList.Add("101290801");
            placeList.Add("101290901");
            placeList.Add("101291001");
            placeList.Add("101291101");
            placeList.Add("101291201");
            placeList.Add("101291301");
            placeList.Add("101291401");
            placeList.Add("101291501");
            placeList.Add("101291601");
            placeList.Add("101300101");
            placeList.Add("101300201");
            placeList.Add("101300301");
            placeList.Add("101300401");
            placeList.Add("101300501");
            placeList.Add("101300601");
            placeList.Add("101300701");
            placeList.Add("101300801");
            placeList.Add("101300901");
            placeList.Add("101301001");
            placeList.Add("101301101");
            placeList.Add("101301201");
            placeList.Add("101301301");
            placeList.Add("101301401");
            placeList.Add("101310101");
            placeList.Add("101310201");
            placeList.Add("101320101");
            placeList.Add("101330101");
            placeList.Add("101340101");
            placeList.Add("101340103");
            placeList.Add("101340201");
            placeList.Add("101340202");
            placeList.Add("101340203");
            placeList.Add("101340401");
            placeList.Add("104010100");
            
            List<string> cityList = new List<string>();
            cityList.Add("北京");
            cityList.Add("上海");
            cityList.Add("天津");
            cityList.Add("重庆");
            cityList.Add("哈尔滨");
            cityList.Add("齐齐哈尔");
            cityList.Add("牡丹江");
            cityList.Add("佳木斯");
            cityList.Add("绥化");
            cityList.Add("黑河");
            cityList.Add("大兴安岭");
            cityList.Add("乌兰浩特");
            cityList.Add("伊春");
            cityList.Add("大庆");
            cityList.Add("七台河");
            cityList.Add("鸡西");
            cityList.Add("鹤岗");
            cityList.Add("双鸭山");
            cityList.Add("长春");
            cityList.Add("吉林");
            cityList.Add("延吉");
            cityList.Add("四平");
            cityList.Add("通化");
            cityList.Add("白城");
            cityList.Add("辽源");
            cityList.Add("松原");
            cityList.Add("白山");
            cityList.Add("沈阳");
            cityList.Add("大连");
            cityList.Add("鞍山");
            cityList.Add("抚顺");
            cityList.Add("本溪");
            cityList.Add("丹东");
            cityList.Add("锦州");
            cityList.Add("营口");
            cityList.Add("阜新");
            cityList.Add("辽阳");
            cityList.Add("铁岭");
            cityList.Add("朝阳");
            cityList.Add("盘锦");
            cityList.Add("葫芦岛");
            cityList.Add("呼和浩特");
            cityList.Add("包头");
            cityList.Add("乌海");
            cityList.Add("乌兰察布");
            cityList.Add("通辽");
            cityList.Add("赤峰");
            cityList.Add("鄂尔多斯");
            cityList.Add("巴彦淖尔");
            cityList.Add("锡林浩特");
            cityList.Add("呼伦贝尔");
            cityList.Add("阿拉善");
            cityList.Add("石家庄");
            cityList.Add("保定");
            cityList.Add("张家口");
            cityList.Add("承德");
            cityList.Add("唐山");
            cityList.Add("廊坊");
            cityList.Add("沧州");
            cityList.Add("衡水");
            cityList.Add("邢台");
            cityList.Add("邯郸");
            cityList.Add("秦皇岛");
            cityList.Add("太原");
            cityList.Add("大同");
            cityList.Add("阳泉");
            cityList.Add("晋中");
            cityList.Add("长治");
            cityList.Add("晋城");
            cityList.Add("临汾");
            cityList.Add("运城");
            cityList.Add("朔州");
            cityList.Add("忻州");
            cityList.Add("吕梁");
            cityList.Add("西安");
            cityList.Add("咸阳");
            cityList.Add("延安");
            cityList.Add("榆林");
            cityList.Add("渭南");
            cityList.Add("商洛");
            cityList.Add("安康");
            cityList.Add("汉中");
            cityList.Add("宝鸡");
            cityList.Add("铜川");
            cityList.Add("济南");
            cityList.Add("青岛");
            cityList.Add("淄博");
            cityList.Add("德州");
            cityList.Add("烟台");
            cityList.Add("潍坊");
            cityList.Add("济宁");
            cityList.Add("泰安");
            cityList.Add("临沂");
            cityList.Add("菏泽");
            cityList.Add("滨州");
            cityList.Add("东营");
            cityList.Add("威海");
            cityList.Add("枣庄");
            cityList.Add("日照");
            cityList.Add("莱芜");
            cityList.Add("聊城");
            cityList.Add("乌鲁木齐");
            cityList.Add("克拉玛依");
            cityList.Add("石河子");
            cityList.Add("昌吉");
            cityList.Add("吐鲁番");
            cityList.Add("库尔勒");
            cityList.Add("阿克苏");
            cityList.Add("喀什");
            cityList.Add("伊宁");
            cityList.Add("塔城");
            cityList.Add("哈密");
            cityList.Add("和田");
            cityList.Add("阿勒泰");
            cityList.Add("博乐");
            cityList.Add("拉萨");
            cityList.Add("日喀则");
            cityList.Add("山南");
            cityList.Add("林芝");
            cityList.Add("昌都");
            cityList.Add("那曲");
            cityList.Add("阿里");
            cityList.Add("西宁");
            cityList.Add("海东");
            cityList.Add("黄南");
            cityList.Add("海南");
            cityList.Add("果洛");
            cityList.Add("玉树");
            cityList.Add("海西");
            cityList.Add("海北");
            cityList.Add("兰州");
            cityList.Add("定西");
            cityList.Add("平凉");
            cityList.Add("庆阳");
            cityList.Add("武威");
            cityList.Add("金昌");
            cityList.Add("张掖");
            cityList.Add("酒泉");
            cityList.Add("天水");
            cityList.Add("临夏");
            cityList.Add("合作");
            cityList.Add("白银");
            cityList.Add("嘉峪关");
            cityList.Add("银川");
            cityList.Add("石嘴山");
            cityList.Add("吴忠");
            cityList.Add("固原");
            cityList.Add("中卫");
            cityList.Add("郑州");
            cityList.Add("安阳");
            cityList.Add("新乡");
            cityList.Add("许昌");
            cityList.Add("平顶山");
            cityList.Add("信阳");
            cityList.Add("南阳");
            cityList.Add("开封");
            cityList.Add("洛阳");
            cityList.Add("商丘");
            cityList.Add("焦作");
            cityList.Add("鹤壁");
            cityList.Add("濮阳");
            cityList.Add("周口");
            cityList.Add("漯河");
            cityList.Add("驻马店");
            cityList.Add("三门峡");
            cityList.Add("济源");
            cityList.Add("南京");
            cityList.Add("无锡");
            cityList.Add("镇江");
            cityList.Add("苏州");
            cityList.Add("南通");
            cityList.Add("扬州");
            cityList.Add("盐城");
            cityList.Add("徐州");
            cityList.Add("淮安");
            cityList.Add("连云港");
            cityList.Add("常州");
            cityList.Add("泰州");
            cityList.Add("宿迁");
            cityList.Add("武汉");
            cityList.Add("襄阳");
            cityList.Add("鄂州");
            cityList.Add("孝感");
            cityList.Add("黄冈");
            cityList.Add("黄石");
            cityList.Add("咸宁");
            cityList.Add("荆州");
            cityList.Add("宜昌");
            cityList.Add("恩施");
            cityList.Add("十堰");
            cityList.Add("神农架");
            cityList.Add("随州");
            cityList.Add("荆门");
            cityList.Add("天门");
            cityList.Add("仙桃");
            cityList.Add("潜江");
            cityList.Add("杭州");
            cityList.Add("湖州");
            cityList.Add("嘉兴");
            cityList.Add("宁波");
            cityList.Add("绍兴");
            cityList.Add("台州");
            cityList.Add("温州");
            cityList.Add("丽水");
            cityList.Add("金华");
            cityList.Add("衢州");
            cityList.Add("舟山");
            cityList.Add("合肥");
            cityList.Add("蚌埠");
            cityList.Add("芜湖");
            cityList.Add("淮南");
            cityList.Add("马鞍山");
            cityList.Add("安庆");
            cityList.Add("宿州");
            cityList.Add("阜阳");
            cityList.Add("亳州");
            cityList.Add("黄山");
            cityList.Add("滁州");
            cityList.Add("淮北");
            cityList.Add("铜陵");
            cityList.Add("宣城");
            cityList.Add("六安");
            cityList.Add("巢湖");
            cityList.Add("池州");
            cityList.Add("福州");
            cityList.Add("厦门");
            cityList.Add("宁德");
            cityList.Add("莆田");
            cityList.Add("泉州");
            cityList.Add("漳州");
            cityList.Add("龙岩");
            cityList.Add("三明");
            cityList.Add("南平");
            cityList.Add("南昌");
            cityList.Add("九江");
            cityList.Add("上饶");
            cityList.Add("抚州");
            cityList.Add("宜春");
            cityList.Add("吉安");
            cityList.Add("赣州");
            cityList.Add("景德镇");
            cityList.Add("萍乡");
            cityList.Add("新余");
            cityList.Add("鹰潭");
            cityList.Add("长沙");
            cityList.Add("湘潭");
            cityList.Add("株洲");
            cityList.Add("衡阳");
            cityList.Add("郴州");
            cityList.Add("常德");
            cityList.Add("益阳");
            cityList.Add("桃江");
            cityList.Add("娄底");
            cityList.Add("邵阳");
            cityList.Add("岳阳");
            cityList.Add("张家界");
            cityList.Add("怀化");
            cityList.Add("永州");
            cityList.Add("吉首");
            cityList.Add("贵阳");
            cityList.Add("遵义");
            cityList.Add("安顺");
            cityList.Add("都匀");
            cityList.Add("凯里");
            cityList.Add("铜仁");
            cityList.Add("毕节");
            cityList.Add("水城");
            cityList.Add("兴义");
            cityList.Add("成都");
            cityList.Add("攀枝花");
            cityList.Add("自贡");
            cityList.Add("绵阳");
            cityList.Add("南充");
            cityList.Add("达州");
            cityList.Add("遂宁");
            cityList.Add("广安");
            cityList.Add("巴中");
            cityList.Add("泸州");
            cityList.Add("宜宾");
            cityList.Add("内江");
            cityList.Add("资阳");
            cityList.Add("乐山");
            cityList.Add("眉山");
            cityList.Add("凉山");
            cityList.Add("雅安");
            cityList.Add("甘孜");
            cityList.Add("阿坝");
            cityList.Add("德阳");
            cityList.Add("广元");
            cityList.Add("广州");
            cityList.Add("韶关");
            cityList.Add("惠州");
            cityList.Add("梅州");
            cityList.Add("汕头");
            cityList.Add("深圳");
            cityList.Add("珠海");
            cityList.Add("佛山");
            cityList.Add("肇庆");
            cityList.Add("湛江");
            cityList.Add("江门");
            cityList.Add("河源");
            cityList.Add("清远");
            cityList.Add("云浮");
            cityList.Add("潮州");
            cityList.Add("东莞");
            cityList.Add("中山");
            cityList.Add("阳江");
            cityList.Add("揭阳");
            cityList.Add("茂名");
            cityList.Add("汕尾");
            cityList.Add("昆明");
            cityList.Add("大理");
            cityList.Add("红河");
            cityList.Add("曲靖");
            cityList.Add("保山");
            cityList.Add("文山");
            cityList.Add("玉溪");
            cityList.Add("楚雄");
            cityList.Add("普洱");
            cityList.Add("昭通");
            cityList.Add("临沧");
            cityList.Add("怒江");
            cityList.Add("迪庆");
            cityList.Add("丽江");
            cityList.Add("德宏");
            cityList.Add("西双版纳");
            cityList.Add("南宁");
            cityList.Add("崇左");
            cityList.Add("柳州");
            cityList.Add("来宾");
            cityList.Add("桂林");
            cityList.Add("梧州");
            cityList.Add("贺州");
            cityList.Add("贵港");
            cityList.Add("玉林");
            cityList.Add("百色");
            cityList.Add("钦州");
            cityList.Add("河池");
            cityList.Add("北海");
            cityList.Add("防城港");
            cityList.Add("海口");
            cityList.Add("三亚");
            cityList.Add("香港");
            cityList.Add("澳门");
            cityList.Add("台北");
            cityList.Add("新竹");
            cityList.Add("高雄");
            cityList.Add("嘉义");
            cityList.Add("台南");
            cityList.Add("台中");
            cityList.Add("新加坡");
            #endregion

            //string city = placeName;
            string city = string.Empty;
            int len = placeName.Length;
            //string xian = city.Substring (len-1, 1);
            if ((len > 2) && Regex.IsMatch(placeName.Substring(len - 1, 1), "县|市|区|旗"))
            {
                city = placeName.Substring(0, len - 1);
            }
            else
            {
                city = placeName;
            }
            if (placeList.Contains(placeWeatherId) || cityList.Contains(placeName))
            {
                Logger.logger("DDDDD id :" + placeWeatherId + " placeName:" + placeName);
            }
            else
            {
                Logger.logger("('" + placeWeatherId + "', '######', 'N/A', '" + city + "', 'N/A'),");
            }
            
        }
        static string GetWeatherForecaset_foreCastPage()
        {
            string forecast = string.Empty;

            DateTime iNow = DateTime.Now;
            string sDay = iNow.ToString("dd");
            string sDay_Y = iNow.AddDays(-1).ToString("dd"); //昨天
            string sHour = "\\d+";

            string url = "http://www.weather.com.cn/forecast/index.shtml";
            string returnHtml = HttpWeb.HttpGetRequestForWeather(url);

            //string pattern = "<p>未来三天具体预报" + iNow.ToString("dd") + "日" + sHour + "时至" + iNow.AddDays(+1).ToString("dd") + "日" + sHour + "时，(.+?)</p>";
            string pattern = "<p>未来三天具体预报.+?时，(.+?)</p>";
            Match m = Regex.Match(returnHtml, pattern);
            if (m != null)
            {
                forecast = m.Groups[1].Value.ToString();
            }
            if (string.IsNullOrEmpty(forecast))
            {
                return forecast;
            }
            else if (forecast.Length > 90)
            {
                return "#天气预报#"+forecast;
            }
            else
            {
                DateTime dt = DateTime.Now;
                ChineseCalendar cc = new ChineseCalendar(dt);
                //Logger.logger("阳历：" + cc.DateString);
                //Logger.logger("属相：" + cc.AnimalString);
                //Logger.logger("农历：" + cc.ChineseDateString);
                //Logger.logger("时辰：" + cc.ChineseHour);
                //Logger.logger("节气：" + cc.ChineseTwentyFourDay);
                //Logger.logger("节日：" + cc.DateHoliday);
                //Logger.logger("前一个节气：" + cc.ChineseTwentyFourPrevDay);
                //Logger.logger("后一个节气：" + cc.ChineseTwentyFourNextDay);
                //Logger.logger("干支：" + cc.GanZhiDateString);
                //Logger.logger("星期：" + cc.WeekDayStr);
                //Logger.logger("星宿：" + cc.ChineseConstellation);
                //Logger.logger("星座：" + cc.Constellation);

                Dictionary<string, string> replaces = new Dictionary<string, string>();
                replaces.Add("雨", "雨[下雨]");
                replaces.Add("雪", "雪[雪]");
                replaces.Add("有", "施");
                //replaces.Add("云", "云[浮云]");
                foreach (var item in replaces)
                {
                    string newforecaset = forecast.Replace(item.Key, item.Value);
                    forecast = newforecaset;
                }
                //string foreExt = "[威武]奉天承运，玉帝诏曰【天庭风雨令第" + iNow.ToString("yyyy") + iNow.ToString("MM") + iNow.ToString("dd") + "号】：";
                string foreExt = "[威武]奉天承运，玉帝[帅]诏曰：";
                return foreExt + forecast + "钦此[叹号]" + cc.ChineseDateString + "";
            }


        }
        static string GetWeatherForecaset_SixDays(string weatherID)
        {
            string url = "http://m.weather.com.cn/data/" + weatherID + ".html";
            string returnHtml = HttpWeb.HttpGetRequestForWeather(url);

            JObject ja = (JObject)JsonConvert.DeserializeObject(returnHtml);
            string city = ja["weatherinfo"]["city"].ToString();
            string city_en = ja["weatherinfo"]["city_en"].ToString();
            string temp1 = ja["weatherinfo"]["temp1"].ToString();
            string temp2 = ja["weatherinfo"]["temp2"].ToString();
            string temp3 = ja["weatherinfo"]["temp3"].ToString();
            string weather1 = ja["weatherinfo"]["weather1"].ToString();
            string weather2 = ja["weatherinfo"]["weather2"].ToString();
            string weather3 = ja["weatherinfo"]["weather3"].ToString();

            string index_d = ja["weatherinfo"]["index_d"].ToString();
            string tips = string.Empty;
            if (!string.IsNullOrEmpty(index_d))
            {
                tips = "王母娘娘说了，" + Regex.Replace(index_d, "年老体弱者.+?。|体弱者.+?。", "", RegexOptions.IgnoreCase);
                string temp = tips.Replace("建议", "爱卿须");
                tips = temp;
            }
            
            //Dictionary<int, WeatherInfo> MyType = new Dictionary<int, WeatherInfo>();
            //for (int i = 1; i <= 9; i++)
            //{
            //    WeatherInfo element = new WeatherInfo();
                
            //    MyType.Add(i, element);
            //}
            string content = string.Empty;
            DateTime iNow = DateTime.Now;
            string iYear = iNow.Year.ToString();
            string iMonth = iNow.Month.ToString();
            string iDay = iNow.Day.ToString();
            string iHour = iNow.ToString("HH");
   
            if (iNow.Hour < 12)
            {
                content = "，玉帝派小神通知你，" + city + "天气施布如下 今天：" + temp1 + " " + weather1 + " ，明天：" + temp2 + " " + weather2 + " ，后天：" + temp3 + " " + weather3 + " 。" + tips;
            }
            else
            {
                content = "，玉帝派小神通知你，" + city + "天气施布如下 明天：" + temp1 + " " + weather1 + " ，后天：" + temp2 + " " + weather2 + " ，大后天：" + temp3 + " " + weather3 + " 。" + tips;
            }

            string[] replaces_old = " 多云转阴 | 晴转多云 | 多云转晴 | 晴 | 阴 | 多云 | 阴转多云 | 小雨 | 中雨 | 大雨 | 阵雨 | 雷阵雨 | 暴雨 | 小雪 | 中雪 | 大雪 | 阵雪 | 暴雪 | 雾 ".Split('|');
            string[] replaces_new = " 多云转阴[浮云]| 晴转多云[晴转多云]| 多云转晴[多云转晴]| 晴[阳光]| 阴[浮云]| 多云[阴天]| 阴转多云[浮云]| 小雨[下雨]| 中雨[下雨]| 大雨[下雨]| 阵雨[下雨]| 雷阵雨[下雨]| 暴雨[下雨]| 小雪[雪]| 中雪[雪]| 大雪[雪]| 阵雪[雪]| 暴雪[雪]| 雾[雾]".Split('|');
            for (int i = 0; i < replaces_old.Length; i++)
            {
                string newContent = content.Replace(replaces_old[i], replaces_new[i]);
                content = newContent;
            }

            return content;

        }
        static void String2Json()
        {
            string jsonText = "{\"weatherinfo\":{\"city\":\"海淀\",\"city_en\":\"haidian\",\"date_y\":\"2013年1月17日\",\"date\":\"\",\"week\":\"星期四\",\"fchh\":\"18\",\"cityid\":\"101010200\",\"temp1\":\"-8℃~3℃\",\"temp2\":\"-6℃~2℃\",\"temp3\":\"-3℃~-1℃\",\"temp4\":\"-5℃~4℃\",\"temp5\":\"-8℃~2℃\",\"temp6\":\"-7℃~4℃\",\"tempF1\":\"17.6℉~37.4℉\",\"tempF2\":\"21.2℉~35.6℉\",\"tempF3\":\"26.6℉~30.2℉\",\"tempF4\":\"23℉~39.2℉\",\"tempF5\":\"17.6℉~35.6℉\",\"tempF6\":\"19.4℉~39.2℉\",\"weather1\":\"晴\",\"weather2\":\"晴转阴\",\"weather3\":\"小雪\",\"weather4\":\"多云\",\"weather5\":\"晴\",\"weather6\":\"多云\",\"img1\":\"0\",\"img2\":\"99\",\"img3\":\"0\",\"img4\":\"2\",\"img5\":\"14\",\"img6\":\"99\",\"img7\":\"1\",\"img8\":\"99\",\"img9\":\"0\",\"img10\":\"99\",\"img11\":\"1\",\"img12\":\"99\",\"img_single\":\"0\",\"img_title1\":\"晴\",\"img_title2\":\"晴\",\"img_title3\":\"晴\",\"img_title4\":\"阴\",\"img_title5\":\"小雪\",\"img_title6\":\"小雪\",\"img_title7\":\"多云\",\"img_title8\":\"多云\",\"img_title9\":\"晴\",\"img_title10\":\"晴\",\"img_title11\":\"多云\",\"img_title12\":\"多云\",\"img_title_single\":\"晴\",\"wind1\":\"微风\",\"wind2\":\"微风\",\"wind3\":\"微风\",\"wind4\":\"微风转北风3-4级\",\"wind5\":\"北风3-4级转微风\",\"wind6\":\"微风\",\"fx1\":\"微风\",\"fx2\":\"微风\",\"fl1\":\"小于3级\",\"fl2\":\"小于3级\",\"fl3\":\"小于3级\",\"fl4\":\"小于3级转3-4级\",\"fl5\":\"3-4级转小于3级\",\"fl6\":\"小于3级\",\"index\":\"冷\",\"index_d\":\"天气冷，建议着棉衣、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣或冬大衣。\",\"index48\":\"冷\",\"index48_d\":\"天气冷，建议着棉衣、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣或冬大衣。\",\"index_uv\":\"弱\",\"index48_uv\":\"最弱\",\"index_xc\":\"较适宜\",\"index_tr\":\"较适宜\",\"index_co\":\"较不舒适\",\"st1\":\"2\",\"st2\":\"-6\",\"st3\":\"3\",\"st4\":\"-4\",\"st5\":\"0\",\"st6\":\"-4\",\"index_cl\":\"适宜\",\"index_ls\":\"基本适宜\",\"index_ag\":\"极不易发\"}}";
            JObject ja = (JObject)JsonConvert.DeserializeObject(jsonText);
            string city = ja["weatherinfo"]["city"].ToString();
            string city_en = ja["weatherinfo"]["city_en"].ToString();
        }
        static void SendFengYuLing()
        {
            string forecast = GetWeatherForecaset_foreCastPage();
            //string calendar = GetPermanentCalendar();
            //string adv = " 本神微信账号：WeatherGod，支持400多个城市，支持名称、拼音、区号、邮编查询，智能记忆查询。不用输入任何文字也能查天气，你一定没用过！【转发有赏】";
            string adv = "[扫描下面微信二维码有更好玩的]";
            string weibo = forecast + adv;

            NetDimension.Weibo.Entities.status.Entity statusInfo = null;
            if (!string.IsNullOrEmpty(weibo))
            {
                byte[] OpenedPicture = Picture.OpenFile("weathergod_430.jpg");
                if (OpenedPicture != null)
                {
                    statusInfo = Weibo_tianqi.API.Entity.Statuses.Upload(weibo, OpenedPicture);
                }
                else
                {
                    statusInfo = Weibo_tianqi.API.Entity.Statuses.Update(weibo);
                }
                Logger.logger("发布成功。Text:" + statusInfo.Text.Substring(0, (statusInfo.Text.Length < 20) ? statusInfo.Text.Length : 20));
            }
        }
        #endregion

        #region Thread
        void threadFunction()
        {
            Thread thLoad = new Thread(new ThreadStart(delegate()
            {
                this.UIInvoke(() =>
                {
                    string topUid = "2044473285,1751675285";
                    string[] splittopUid = topUid.Split(',');
                    for (int i = 0; i < splittopUid.Length; i++)
                    {
                        GetAtSomebodyFromUid(splittopUid[i]);
                    }

                });
            }));
            thLoad.IsBackground = true;
            thLoad.Start();
        }
        #endregion

        #region calender
        static void SendDailyTips()
        {
            //string weibo = GetWeatherForecaset_foreCastPage();
            string calendar = GetPermanentCalendar();
            //string adv = " 本神微信账号：WeatherGod，支持400多个城市，支持名称、拼音、区号、邮编查询，智能记忆查询。不用输入任何文字也能查天气，你一定没用过！【转发有赏】";
            //string adv = "【转发获天气，评论领红包】";
            string adv = "";
            //string weibo = "#让红包飞#" + calendar + adv;
            string weibo = calendar + adv;

            NetDimension.Weibo.Entities.status.Entity statusInfo = null;
            if (!string.IsNullOrEmpty(weibo))
            {
                statusInfo = Weibo_tianqi.API.Entity.Statuses.Update(weibo);
                Logger.logger("发布成功。Text:" + statusInfo.Text.Substring(0, (statusInfo.Text.Length < 20) ? statusInfo.Text.Length : 20));
            }
        }
        static string GetPermanentCalendar()
        {
            string pc = string.Empty;
            DateTime dt = DateTime.Now;
            string yangli = "今天是" + dt.Year.ToString() + "年" + dt.Month.ToString() + "月" + dt.Day.ToString() + "日";

            ChineseCalendar cc = new ChineseCalendar(dt);
            //Logger.logger("星期：" + cc.WeekDayStr);
            //Logger.logger("属相：" + cc.AnimalString);
            //Logger.logger("农历：" + cc.ChineseDateString);
            string nongli = cc.ChineseDateString;
            //Logger.logger("时辰：" + cc.ChineseHour);
            //Logger.logger("节气：" + cc.ChineseTwentyFourDay);
            string jieqi = (cc.ChineseTwentyFourDay == "")?"":" 节气：" + cc.ChineseTwentyFourDay;

            //Logger.logger("节日：" + cc.DateHoliday + cc.ChineseCalendarHoliday);
            string jieri = (cc.DateHoliday + cc.ChineseCalendarHoliday == "") ? "" : " 节日：" + cc.ChineseCalendarHoliday + " " + cc.DateHoliday;
            //Logger.logger("前一个节气：" + cc.ChineseTwentyFourPrevDay);
            //Logger.logger("后一个节气：" + cc.ChineseTwentyFourNextDay);
            //Logger.logger("干支：" + cc.GanZhiDateString);
            //Logger.logger("星宿：" + cc.ChineseConstellation);
            //Logger.logger("星座：" + cc.Constellation);
            pc = yangli + " " + cc.WeekDayStr + " " + cc.ChineseDateString + " [" + cc.AnimalString + "]" + cc.GanZhiDateString + jieqi + jieri + " 星宿:" + cc.ChineseConstellation + " 星座:" + cc.Constellation;
            return pc;
        }
        #endregion

        #region Test
        static void DebugModeTest()
        {

            try
            {
                SendFengYuLing();
                GetWeatherInfoNodeFromXML();
                SendDailyTips();
                string x = GetPermanentCalendar();
                RandomReplyWeiboByKeyword("天气");
                ReplyWeiboAtMe();
                
                //ReplyWeiboByKeyword("PM2.5");
                ReplyWeiboAtMe();
                string a = GetWeatherForecaset_SixDays("101010100");
                //string jsonText1 = "[{'a':'aaa','b':'bbb','c':'ccc'},{'a':'aaa2','b':'bbb2','c':'ccc2'}]";
                //JArray ja = (JArray)JsonConvert.DeserializeObject(jsonText1);
                //JObject o = (JObject)ja[1];
                //Console.WriteLine(o["a"]);
                //Console.WriteLine(ja[1]["a"]);
                string jsonText = "{\"weatherinfo\":{\"city\":\"海淀\",\"city_en\":\"haidian\",\"date_y\":\"2013年1月17日\",\"date\":\"\",\"week\":\"星期四\",\"fchh\":\"18\",\"cityid\":\"101010200\",\"temp1\":\"-8℃~3℃\",\"temp2\":\"-6℃~2℃\",\"temp3\":\"-3℃~-1℃\",\"temp4\":\"-5℃~4℃\",\"temp5\":\"-8℃~2℃\",\"temp6\":\"-7℃~4℃\",\"tempF1\":\"17.6℉~37.4℉\",\"tempF2\":\"21.2℉~35.6℉\",\"tempF3\":\"26.6℉~30.2℉\",\"tempF4\":\"23℉~39.2℉\",\"tempF5\":\"17.6℉~35.6℉\",\"tempF6\":\"19.4℉~39.2℉\",\"weather1\":\"晴\",\"weather2\":\"晴转阴\",\"weather3\":\"小雪\",\"weather4\":\"多云\",\"weather5\":\"晴\",\"weather6\":\"多云\",\"img1\":\"0\",\"img2\":\"99\",\"img3\":\"0\",\"img4\":\"2\",\"img5\":\"14\",\"img6\":\"99\",\"img7\":\"1\",\"img8\":\"99\",\"img9\":\"0\",\"img10\":\"99\",\"img11\":\"1\",\"img12\":\"99\",\"img_single\":\"0\",\"img_title1\":\"晴\",\"img_title2\":\"晴\",\"img_title3\":\"晴\",\"img_title4\":\"阴\",\"img_title5\":\"小雪\",\"img_title6\":\"小雪\",\"img_title7\":\"多云\",\"img_title8\":\"多云\",\"img_title9\":\"晴\",\"img_title10\":\"晴\",\"img_title11\":\"多云\",\"img_title12\":\"多云\",\"img_title_single\":\"晴\",\"wind1\":\"微风\",\"wind2\":\"微风\",\"wind3\":\"微风\",\"wind4\":\"微风转北风3-4级\",\"wind5\":\"北风3-4级转微风\",\"wind6\":\"微风\",\"fx1\":\"微风\",\"fx2\":\"微风\",\"fl1\":\"小于3级\",\"fl2\":\"小于3级\",\"fl3\":\"小于3级\",\"fl4\":\"小于3级转3-4级\",\"fl5\":\"3-4级转小于3级\",\"fl6\":\"小于3级\",\"index\":\"冷\",\"index_d\":\"天气冷，建议着棉衣、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣或冬大衣。\",\"index48\":\"冷\",\"index48_d\":\"天气冷，建议着棉衣、皮夹克加羊毛衫等冬季服装。年老体弱者宜着厚棉衣或冬大衣。\",\"index_uv\":\"弱\",\"index48_uv\":\"最弱\",\"index_xc\":\"较适宜\",\"index_tr\":\"较适宜\",\"index_co\":\"较不舒适\",\"st1\":\"2\",\"st2\":\"-6\",\"st3\":\"3\",\"st4\":\"-4\",\"st5\":\"0\",\"st6\":\"-4\",\"index_cl\":\"适宜\",\"index_ls\":\"基本适宜\",\"index_ag\":\"极不易发\"}}";
                JObject ja = (JObject)JsonConvert.DeserializeObject(jsonText);
                string city = ja["weatherinfo"]["city"].ToString();
                string city_en = ja["weatherinfo"]["city_en"].ToString();

            }
            catch (Exception ex)
            {
                Logger.logger("DEBUG " + ex.Message);
            }
            finally
            {
                Logger.logger(string.Empty);
            }
        }
        #endregion
    }
}
